﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Demo.IDAL;
using System.Reflection;

namespace Demo.DALFactory
{
    #region 新闻工厂:NewsFactory
    /// <summary>
    /// 新闻工厂
    /// </summary>
    public class NewsFactory
    {
        #region 创建“新闻”这个产品的实例
        /// <summary>
        /// 创建“新闻”这个产品的实例
        /// </summary>
        /// <returns></returns>
        public static INewsService CreateNewsService()
        {
            //获取SQLServerDAL程序集路径
            string strDalPath = System.Configuration.ConfigurationManager.AppSettings["WebDAL"].ToString();

            //获取 位于DAL程序集路径下的NewsService类名
            string strClassName = strDalPath + ".NewsService";

            Type objType = Type.GetType(strClassName, true);

            // 详情参见：http://www.cnblogs.com/dudu837/archive/2009/09/06/1561249.html
            return (INewsService)Activator.CreateInstance(objType);

            //反射获取程序集、新闻类的实例
           // return (INewsService)Assembly.Load(strDalPath).CreateInstance(strClassName);



        }
        #endregion

    }
    #endregion
}
